package service.edu.controller;


import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.web.multipart.MultipartFile;
import service.edu.entity.subject.FirstSubject;
import service.edu.service.SubjectService;
import service.edu.result.R;

import java.util.List;

/**
 * <p>
 * 课程科目 前端控制器
 * </p>
 *
 * @author diao
 * @since 2020-08-04
 */
@RestController
@RequestMapping("/edu/subject")
@CrossOrigin
public class SubjectController {
    @Autowired
    private SubjectService subjectService;

    @ApiOperation("添加课程分类功能")
    @PostMapping("/addSubject")
    public R addSubject(@ApiParam(name = "file",value = "上传的excel文件") MultipartFile file){
         subjectService.saveSubject(file,subjectService);
         return R.Ok();
    }

    @ApiOperation("以树形形式显示课程列表")
    @GetMapping("/querySubject")
    public R querySubject(){
         //一级分类的属性包含二级分类
         List<FirstSubject> subjectList= subjectService.getAllSubjects();
        return R.Ok().data("subjectList",subjectList);
    }
}

